<?php
class DvthicongsController extends AppController {

	var $name = 'Dvthicongs';
	var $uses= array('Ctrinh','Dvthicong' );
	function index() {
		$this->Dvthicong->recursive = -1;
		$this->set('dvthicongs', $this->paginate('Dvthicong'));
		//print_r($dvthicongs);
		
	}


	function cttc($idtc) {
		$this->Dvthicong->recursive = -1;
		$tc=$this->Dvthicong->find('first', array('id' => $idtc));
		$this->Ctrinh->recursive = 0;
		$this->set('ctrinhs', $this->paginate('Ctrinh', array('dvthicong_id' =>$idtc)));
		$this->set(compact('tc'));
	}
	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid dvthicong', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('dvthicong', $this->Dvthicong->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Dvthicong->create();
			if ($this->Dvthicong->save($this->data)) {
				$this->Session->setFlash(__('The dvthicong has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Dữ liệu được lưu, vui lòng thử lại', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid dvthicong', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Dvthicong->save($this->data)) {
				$this->Session->setFlash(__('The dvthicong has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Dữ liệu được lưu, vui lòng thử lại', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Dvthicong->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for dvthicong', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Dvthicong->delete($id)) {
			$this->Session->setFlash(__('Dvthicong deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Dữ liệu được lưu, vui lòng thử lại', true));
		$this->redirect(array('action' => 'index'));
	}
}
